const Service = require('../../../core/service/ApiService');

class AgedSvc extends Service {

    //获取老人列表
    async getAgedList(pn, ps) {
        const dao = this.service.tablet.aged.dao;
        return {
            list: await dao.getAgedList(pn, ps)
        }
    }

    //获取老人信息
    async getAged(id) {
        return this.service.tablet.aged.dao.getAged(id)
    }

    //批量提交老人信息
    async import(aged_list) {
        const dao = this.service.tablet.aged.dao;
        const townandcmy = await dao.findtownandcmy();
        for(let i=0;i<aged_list.length;i++)
        {
            for(let j=0;j<townandcmy.length;j++)
            {
                if(aged_list[i].subdistrict_id===townandcmy[j].subdistrict_id)
                {
                    aged_list[i].town_id = townandcmy[j].town_id;
                    aged_list[i].community_id = townandcmy[j].community_id;
                }
            }
        }
        await this.service.tablet.aged.dao.import(aged_list)
    }
}

module.exports = AgedSvc;
